﻿namespace SLClient.Resource.Converters
{
    using System;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;

    public class OpenBonusFormatConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                StackPanel panel;
                Grid grid;
                Image image;
                TextBlock block;
                double num;
                string[] strArray = value.ToString().Split(new char[] { ',' });
                switch (strArray.Length)
                {
                    case 3:
                        panel = new StackPanel();
                        panel.Orientation = Orientation.Horizontal;
                        foreach (string str in strArray)
                        {
                            grid = new Grid();
                            grid.Margin=new Thickness(2.0);
                            image = new Image();
                            image.Height = num = 41.0;
                            image.Width = num;
                            image.Source = new BitmapImage(new Uri("../Images/red_b.png", UriKind.RelativeOrAbsolute));
                            block = new TextBlock();
                            block.HorizontalAlignment = HorizontalAlignment.Center;
                            block.VerticalAlignment = VerticalAlignment.Center;
                            block.Foreground=new SolidColorBrush(Colors.White);
                            block.Style=Application.Current.Resources["styleBonusNumber"] as Style;
                            block.Text = str;
                            grid.Children.Add(image);
                            grid.Children.Add(block);
                            panel.Children.Add(grid);
                        }
                        return panel;

                    case 5:
                        panel = new StackPanel();
                        panel.Orientation = Orientation.Horizontal;
                        foreach (string str in strArray)
                        {
                            grid = new Grid();
                            grid.Margin=new Thickness(2.0);
                            image = new Image();
                            image.Height = num = 41.0;
                            image.Width = num;
                            image.Source = new BitmapImage(new Uri("../Images/red_b.png", UriKind.RelativeOrAbsolute));
                            block = new TextBlock();
                            block.HorizontalAlignment = HorizontalAlignment.Center;
                            block.VerticalAlignment = VerticalAlignment.Center;
                            block.Foreground=new SolidColorBrush(Colors.White);
                            block.Style=Application.Current.Resources["styleBonusNumber"] as Style;
                            block.Text=str;
                            grid.Children.Add(image);
                            grid.Children.Add(block);
                            panel.Children.Add(grid);
                        }
                        return panel;

                    case 7:
                        panel = new StackPanel();
                        panel.Orientation = Orientation.Horizontal;
                        for (int i = 0; i < 7; i++)
                        {
                            grid = new Grid();
                            grid.Margin=new Thickness(2.0);
                            image = new Image();
                            image.Height = num = 41.0;
                            image.Width = num;
                            image.Source = new BitmapImage(new Uri("../Images/" + ((i < 6) ? "red" : "blue") + "_b.png", UriKind.RelativeOrAbsolute));
                            block = new TextBlock();
                            block.HorizontalAlignment = HorizontalAlignment.Center;
                            block.VerticalAlignment = VerticalAlignment.Center;
                            block.Foreground = new SolidColorBrush(Colors.White);
                            block.Style = Application.Current.Resources["styleBonusNumber"] as Style;
                            block.Text=strArray[i];
                            grid.Children.Add(image);
                            grid.Children.Add(block);
                            panel.Children.Add(grid);
                        }
                        return panel;
                }
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

